package com.wwg.design.patten.observer.case1;

import java.util.List;

/**
 * @类描述: 观察这抽象
 * @Author wwg
 * @date: 2021/7/20 18:47
 * @Version: 1.0
 **/
public abstract class AbstractObserver implements IObserver {

    /**
     * 名字
     */
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Subject> getSubjects() {
        return subjects;
    }

    public void setSubjects(List<Subject> subjects) {
        this.subjects = subjects;
    }

    /**
     * 观察这对象订阅的主体列表
     */
    private List<Subject> subjects;

    /**
     * 添加主体订阅
     * @param subject
     */
    public void addSubject(Subject subject){
        // 将主体和观察者关联起来
        subject.addObserver(this);

        subjects.add(subject);
    };

    /**
     * 主体回调接口
     * @param someThingHappen
     */
    public abstract void call(String someThingHappen);
}
